<include file="Public:head" title='参考网站' />
<script src="__PUBLIC__/js/other/validate.js"></script>
<style>
    .names{
        width:220px
    }
    </style>
<script type="text/javascript">
    $(function() {
        $("#form").validate({
            errorPlacement: function(error, element) {
                var error_td = element.parent('td');
                error_td.find('label.error').hide();
                error_td.append(error);
            },
            rules: {
                name: {
                    required: true
                },
                url: {
                    url: true
                }

            },
            messages: {
                name: {
                    required: '参考网站名称不能为空'
                },
                url: {
                    url: "清正确填写链接格式"
                }

            }
        });
        $("input[name=state]").click(function() {
            var state = $(this).val();
            if (state == -1) {
                $("#tr_reason").show();
            } else {
                $("#tr_reason").hide();
            }
        })
    });
</script>
<div class="main-container" id="main-container">
    <div class="main-container-inner">
        <include file="Public:left" />
        <div class="main-content">
            <div class="breadcrumbs" id="breadcrumbs">
                <ul class="breadcrumb">
                    <li><i class="icon-home home-icon"></i><a href="__APP__/{$Think.MODULE_NAME}">首页</a></li>
                    <li><a href="{:U('Website/lists')}">参考网站管理</a></li>
                    <li class="active">参考网站{$Think.get.id|getPageType}</li>
                </ul>
            </div>
            <div class="page-content">
                <div class="row">
                    <div class="col-xs-12">
                        <div class="row">
                            <div class="col-xs-12">
                                <h3 class="header smaller lighter blue">参考网站{$Think.get.id|getPageType}</h3>

                                <form action="{:U('Website/detail_post')}" method="POST" id="form">
                                    <table class="table table_detail">
                                        <tbody>
                                            <tr>
                                                <td class="td_left">参考网站名称:</td>
                                                <td>
                                                    <input name="name"  type="text" class="common_txt"  value="{$detail.name}"/>
                                                </td>
                                            </tr>
                                            <tr>
                                                <td class="td_left">模板id:</td>
                                                <td>
                                                    <input name="modal_id"  type="text" class="common_txt"  value="{$detail.modal_id}"/>
                                                </td>
                                            </tr>
                                            <tr>
                                                <td class="td_left">网址:</td>
                                                <td>
                                                    <input name="website"  id="website" type="text" class="common_txt"  value="{$detail.website}"/>
                                                    <a onclick="addFriends()">+添加多个</a>
                                                </td>
                                            </tr>
                                            <tr>
                                                <td class="td_left">网址2:</td>
                                                <td>
                                                    <input name="website2"  type="text" class="common_txt"  value="{$detail.website2}"/>
                                                    <label><input type="checkbox" checked onclick="checkWebsiteAll($(this))" autocomplete="off"/>全选</label>
                                                </td>
                                            </tr>
                                    </table>
                                    <ul id="jsons" class="jsons">
                                        <foreach name="jsons" item="row">
                                            <li class="li_jsons">
                                                <input type="checkbox" name="is_chose" onclick="is_chose2($(this))" checked autocomplete="off"/>
                                                链接：<input class="common_txt urls" type="text" value="{$row.urls}" name="urls[]" onblur="getUrlCode($(this))" autocomplete="off"/>
                                                标识：<input class="common_txt codes" type="text" value="{$row.codes}" name="codes[]" autocomplete="off"/>
                                                名称：<input name='names[]' type='text' class='common_txt names'  value='{$row.names}' autocomplete="off"/>
                                                源链接：<input class="common_txt urls_real" type="text" value="{$row.urls_real}" name="urls_real[]"  autocomplete="off"/>
                                            <if condition="$detail.website2 neq ''">
                                                <select name="website_chose[]" autocomplete="off" class="website_chose">
                                                    <option value="0">{$detail.website}</option>
                                                    <option value="1" <if condition="$row.website_chose eq 1">selected</if>>{$detail.website2}</option>
                                                    <option value="2" <if condition="$row.website_chose eq 2">selected</if>>http://localhost/</option>
                                                </select>
                                            </if>
                                            <a href="__APP__/website/{$detail.name_short}/{$row.codes}.html" target="_blank">查看</a>
                                            <a onclick="$(this).parent().remove()">删除</a>

                                            </li>
                                        </foreach>
                                    </ul>
                                    <table class="table table_detail" >
                                        <tr>
                                            <td class="td_left">备用:</td>
                                            <td>
                                                <a onclick="addFriends2()">+添加多个</a>
                                            </td>
                                        </tr>
                                    </table>
                                    <ul id="jsons2" class="jsons">
                                        <foreach name="jsons2" item="row">
                                            <li class="li_jsons2">
                                                链接：<input class="common_txt urls2" type="text" value="{$row.urls2}" name="urls2[]" onblur="getUrlCode($(this))" autocomplete="off"/>
                                                标识：<input class="common_txt codes2" type="text" value="{$row.codes2}" name="codes2[]" autocomplete="off"/>
                                                名称：<input name='names2[]' type='text' class='common_txt names2'  value='{$row.names2}' autocomplete="off"/>
                                                <a onclick="$(this).parent().remove()">删除</a>
                                            </li>
                                        </foreach>
                                    </ul>
                                    
                                    <table class="table table_detail" >
                                        <tr id="tr_name">
                                            <td class="td_left">排序:</td>
                                            <td>
                                                <input name="ord" type="text" class="common_txt" value="{$detail.ord}" autocomplete="off" />
                                            </td>
                                        </tr>
                                        <tr>
                                            <td class="td_left">审核状态:</td>
                                            <td>
                                                <label>
                                                    <input type="radio" autocomplete="off"  value="0" name="state" {$detail.state|getEqual=###,0,'checked'}>
                                                    等待审核
                                                </label>
                                                <label>
                                                    <input type="radio" autocomplete="off" value="1" name="state" {$detail.state|getEqual=###,1,'checked'}>
                                                    审核完成
                                                </label>
                                                <label>
                                                    <input type="radio" autocomplete="off" value="2" name="state" {$detail.state|getEqual=###,2,'checked'}>
                                                    采集成功
                                                </label>
                                                <label>
                                                    <input type="radio" autocomplete="off" value="-1" name="state" {$detail.state|getEqual=###,-1,'checked'} >
                                                    拒绝通过
                                                </label>
                                            </td>
                                        </tr>
                                        <tr id='tr_reason' <if condition="$detail.state neq -1">style='display:none'</if>>
                                        <td class="td_left">拒绝原因:</td>
                                        <td>
                                            <textarea id="reason" cols="60" rows="8" name="reason">{$detail.reason}</textarea>
                                        </td>
                                        </tr>
                                        <tr>
                                            <td class="td_left"></td>
                                            <td>
                                                <input type='hidden' name='id' value='{$Think.get.id}'/>
                                                <button class="btn btn-info btn-sm" type="submit">
                                                    <i class="icon-ok bigger-110 "></i>
                                                    保 存
                                                </button>

                                                <button class="btn btn-sm reset" type="button" onclick="goUrl(-1)">
                                                    <i class="icon-undo bigger-110"></i>
                                                    返 回
                                                </button>
                                                <button class="btn btn-sm btn-danger" type="button" onclick="modal_get()">
                                                    <i class="icon-beaker align-top bigger-125"></i>
                                                    解压
                                                </button>
                                                <button class="btn btn-sm btn-pink" type="button" onclick="html_format()">
                                                    <i class="icon-exchange  align-top bigger-125"></i>
                                                    格式化
                                                </button>
                                                <button class="btn btn-sm btn-purple" type="button" onclick="html_zip()">
                                                    <i class="icon-certificate  align-top bigger-125"></i>
                                                    生成zip
                                                </button>
                                                <a class="btn btn-sm btn-purple"href="__APP__/website/jd" target="_blank"/>
                                                查看演示
                                                </a>
                                                
                                            </td>
                                        </tr>
                                    </table>
                                    <ul>
                                        <foreach name="nodates" item="row">
                                            <li>
                                                链接：<input class="common_txt"style="width:550px" type="text" value="{$detail.website2}{$row}" name="nodates[]"  autocomplete="off"/>
                                               
                                                <a onclick="$(this).parent().remove()">删除</a>
                                            </li>
                                        </foreach>
                                    </ul>
                                     <button class="btn btn-sm btn-purple" type="button" onclick="modal_link_css_images()">
                                                    <i class="icon-certificate  align-top bigger-125"></i>
                                                    更换链接
                                                </button>
                                    
                                </form>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </div>
        <include file="Public:setting" />
    </div>
</div>
<script>
    function modal_link_css_images() { //获取远程css 和图片
        $.post("{:U('Website/modal_link_css_images')}", {
            id: "{$Think.get.id}"
        }, function(data) {
    
        })
    }
    function addFriends(ul) {
        var li = "<li class='li_jsons'><input type='checkbox' name='is_chose' onclick='s_chose2($(this))' checked autocomplete='off' /> 链接：<input name='urls[]' type='text' class='common_txt urls'  value='' onblur=getUrlCode($(this)) />\n\
标识：<input name='codes[]' type='text' class='common_txt codes'  value=''/>\n\
名称：<input name='names[]' type='text' class='common_txt names'  value=''/>\n\
链接：<input name='urls_real[]' type='text' class='common_txt urls_real'  value='' onblur=getUrlCode($(this)) />\n\
<a onclick=$(this).parent().remove()>删除</a></li>";
        $('#jsons').append(li);
    }
    function addFriends2(ul) {
        var li = "<li class='li_jsons2'>链接：<input name='urls2[]' type='text' class='common_txt urls2'  value='' onblur=getUrlCode($(this)) />\n\
标识：<input name='codes2[]' type='text' class='common_txt codes2'  value=''/>\n\
名称：<input name='names2[]' type='text' class='common_txt names2'  value=''/>\n\
<a onclick=$(this).parent().remove()>删除</a></li>";
        $('#jsons2').append(li);
    }
    function getWebName() {
        var website = $("#website").val();
        website = website.replace("http://", '');
        website = website.replace("www.", '');
        var websiteArr = website.split(".");
        return websiteArr[0];
    }
    function getUrlCode(obj) {
        var site_name = getWebName();
        var url = obj.val();
        url = url.replace("http://", '');
        url = url.replace("www.", '');

        var urlArr = url.split("." + site_name);
        var code = urlArr[0];
        var codeArr = code.split("/");
        if (codeArr.length > 1) {
            code = codeArr[1];
        }
        code = code.toLocaleLowerCase();
        if (code == '') {
            code = 'index';
        }
        var next = obj.next("input.common_txt");
        var next_val = next.val();
        if (!next_val) {
            next.val(code);
        }
        
        if(obj.parent().find('.urls_real').val() == ''){
            obj.parent().find('.urls_real').val(obj.val())
        }

    }
    function modal_get() {
        
       // modal_unzip_css_images("http://kaichiba.com/index.aspx?ct=1&cid=12");
        
        var li_first = $("#jsons").children("li.li_jsons:first")
        var url = li_first.children(".urls").val();
//       url = "http://localhost/m/kaichiba/draw.html";
//modal_unzip_html(url);
//        return false;

        var code = li_first.children(".codes").val();
        var name = li_first.children(".names").val();

        if (li_first.length > 0) {
            modal_unzip_js(url);
        } else {
          html_format();
        }
    }
    function modal_unzip_html(url_post) { //获取html
        var li_first = $("#jsons").children("li.li_jsons:first");
        var code_post = li_first.children(".codes").val();
        var name_post = li_first.children(".names").val();

        $.post("{:U('Website/modal_unzip_html')}", {
            id: "{$Think.get.id}",
            website: $("#website").val(),
            url_post: url_post,
            code_post: code_post,
            name_post: name_post,
            website_chose: $("#jsons").children("li.li_jsons:first").children(".website_chose").find("option:selected").text()

        }, function(data) {
            li_first.removeClass("li_jsons");
           modal_get();
        })
    }
    function modal_unzip_css_images(url_post) { //获取远程css 和图片
        $.post("{:U('Website/modal_unzip_css_images')}", {
            id: "{$Think.get.id}",
            website: $("#website").val(),
            url_post: url_post,
            website_chose: $("#jsons").children("li.li_jsons:first").children(".website_chose").find("option:selected").text()
        }, function(data) {
          modal_unzip_html(url_post)
        })
    }
    function modal_unzip_js(url_post) { //获取远程js
        $.post("{:U('Website/modal_unzip_js')}", {
            id: "{$Think.get.id}",
            website: $("#website").val(),
            url_post: url_post,
            website_chose: $("#jsons").children("li.li_jsons:first").children(".website_chose").find("option:selected").text()
        }, function(data) {
            modal_unzip_css_images(url_post);

        })
    }
    function html_format() {
        $.post("{:U('Website/html_format')}", {
            id: "{$Think.get.id}",
            website: $("#website").val(),
            website_chose: $("#jsons").children("li.li_jsons:first").children(".website_chose").find("option:selected").text()
        }, function(data) {
        })
    }
    function html_zip() {
        $.post("{:U('Website/html_zip')}", {
            id: "{$Think.get.id}",
            website: $("#website").val(),
            website_chose: $("#jsons").children("li.li_jsons:first").children(".website_chose").find("option:selected").text()
        }, function(data) {
        })
    }
    function is_chose2(obj) {
        if (obj.prop("checked") == true) {
            obj.parent("li").addClass("li_jsons");
        } else {
            obj.parent("li").removeClass("li_jsons");
        }
    }
    $('#jsons').sortable({
        connectWith: '.jsons',
        items: '.li_jsons',
        opacity: 0.8,
        revert: true,
        forceHelperSize: true,
        placeholder: 'widget-placeholder',
        forcePlaceholderSize: true,
        tolerance: 'pointer'
    });
    function checkWebsiteAll(obj) {
        if (obj.prop("checked") == false) {
            $("#jsons").find("input[type=checkbox]").removeAttr("checked");
            $("#jsons").find("li").removeClass("li_jsons");
        } else {
            $("#jsons").find("input[type=checkbox]").prop("checked", "checked");
            $("#jsons").find("li").addClass("li_jsons");
        }
    }
</script>

<include file="Public:foot" />